#include <QRectF>
#include <QDebug>
#include "mtqgraphicsview.h"

MTQGraphicsView::MTQGraphicsView( QGraphicsScene * scene, QWidget * parent  ):
        QGraphicsView(scene,parent){
        QMap<int,QGraphicsEllipseItem*> touches;
        }
void MTQGraphicsView::fazBolinha(int touchId, double x, double y, int type){
    QGraphicsScene* s = this->scene();
    QRectF r = this->rect();
    double w = r.width();
    double h = r.height();
    switch (type){
        case 0:
            if(!this->touches.contains(touchId)){
              this->touches[touchId] = s->addEllipse(QRectF(30,30,30,30), QPen(QColor("red")), QBrush(QColor("red"), Qt::SolidPattern));
              this->touches[touchId]->setPos(x*w,y*h);
            }
            break;
        case 1:
           if(this->touches.contains(touchId)){
                QGraphicsEllipseItem* a = this->touches[touchId];
                a->hide();
                this->touches.remove(touchId);
                }
           break;
        case 2:
            if(this->touches.contains(touchId))
                this->touches[touchId]->setPos(x*w,y*h);
            break;

        }
}
void MTQGraphicsView::onTouch(int touchId, double x, double y, int type){
    QRectF r = this->rect();
    double w = r.width();
    double h = r.height();
    this->fazBolinha(touchId,x,y,type);
}
